#lang sicp

(define (square x)
  (* x x))

(define (find-divisor n q)
  (cond ((> (square q) n) n)
        ((divides? n q) q)
        (else (find-divisor n (+ q 1)))))

(define (divides? n q)
  (= (remainder n q) 0))

(define (prime? n)
  (= (find-divisor n 2) n))

;; (find-divisor 199 2)
;; (find-divisor 1999 2)
;; (find-divisor 19999 2)